{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'SomeClass' object has no attribute 'var'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-5c5abe7f5253>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     26\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     27\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 28\u001b[0;31m \u001b[0mSomeClass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msome_method\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-1-5c5abe7f5253>\u001b[0m in \u001b[0;36msome_method\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     19\u001b[0m             \u001b[0;34m...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     20\u001b[0m         \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msome_fn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 21\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0msome_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvar\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0msome_method_2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mT\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'SomeClass' object has no attribute 'var'"
     ]
    }
   ],
   "source": [
    "import typing\n",
    "\n",
    "\n",
    "T = typing.TypeVar(\"T\")\n",
    "U = typing.TypeVar(\"U\")\n",
    "\n",
    "\n",
    "def some_fn(a: U) -> U:\n",
    "    ...\n",
    "\n",
    "f  = None\n",
    "\n",
    "class SomeClass(typing.Generic[T, U]):\n",
    "    var: T\n",
    "\n",
    "    def some_method(self) -> T:\n",
    "        global f\n",
    "        def some_fn(a: U) -> U:\n",
    "            ...\n",
    "        f = some_fn\n",
    "        return some_fn(self.var)\n",
    "\n",
    "    def some_method_2(self) -> T:\n",
    "\n",
    "        return some_fn(self.var)\n",
    "\n",
    "    \n",
    "SomeClass().some_method()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'__name__': '__main__',\n",
       " '__doc__': 'Automatically created module for IPython interactive environment',\n",
       " '__package__': None,\n",
       " '__loader__': None,\n",
       " '__spec__': None,\n",
       " '__builtin__': <module 'builtins' (built-in)>,\n",
       " '__builtins__': <module 'builtins' (built-in)>,\n",
       " '_ih': ['',\n",
       "  'import typing\\n\\n\\nT = typing.TypeVar(\"T\")\\nU = typing.TypeVar(\"U\")\\n\\n\\ndef some_fn(a: U) -> U:\\n    ...\\n\\nf  = None\\n\\nclass SomeClass(typing.Generic[T, U]):\\n    var: T\\n\\n    def some_method(self) -> T:\\n        global f\\n        def some_fn(a: U) -> U:\\n            ...\\n        f = some_fn\\n        return some_fn(self.var)\\n\\n    def some_method_2(self) -> T:\\n\\n        return some_fn(self.var)\\n\\n    \\nSomeClass().some_method()',\n",
       "  'f.__globals__'],\n",
       " '_oh': {},\n",
       " '_dh': ['/Users/saul/p/metadsl/explorations'],\n",
       " 'In': ['',\n",
       "  'import typing\\n\\n\\nT = typing.TypeVar(\"T\")\\nU = typing.TypeVar(\"U\")\\n\\n\\ndef some_fn(a: U) -> U:\\n    ...\\n\\nf  = None\\n\\nclass SomeClass(typing.Generic[T, U]):\\n    var: T\\n\\n    def some_method(self) -> T:\\n        global f\\n        def some_fn(a: U) -> U:\\n            ...\\n        f = some_fn\\n        return some_fn(self.var)\\n\\n    def some_method_2(self) -> T:\\n\\n        return some_fn(self.var)\\n\\n    \\nSomeClass().some_method()',\n",
       "  'f.__globals__'],\n",
       " 'Out': {},\n",
       " 'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x109ea5828>>,\n",
       " 'exit': <IPython.core.autocall.ZMQExitAutocall at 0x109f08710>,\n",
       " 'quit': <IPython.core.autocall.ZMQExitAutocall at 0x109f08710>,\n",
       " '_': '',\n",
       " '__': '',\n",
       " '___': '',\n",
       " '_i': 'import typing\\n\\n\\nT = typing.TypeVar(\"T\")\\nU = typing.TypeVar(\"U\")\\n\\n\\ndef some_fn(a: U) -> U:\\n    ...\\n\\nf  = None\\n\\nclass SomeClass(typing.Generic[T, U]):\\n    var: T\\n\\n    def some_method(self) -> T:\\n        global f\\n        def some_fn(a: U) -> U:\\n            ...\\n        f = some_fn\\n        return some_fn(self.var)\\n\\n    def some_method_2(self) -> T:\\n\\n        return some_fn(self.var)\\n\\n    \\nSomeClass().some_method()',\n",
       " '_ii': '',\n",
       " '_iii': '',\n",
       " '_i1': 'import typing\\n\\n\\nT = typing.TypeVar(\"T\")\\nU = typing.TypeVar(\"U\")\\n\\n\\ndef some_fn(a: U) -> U:\\n    ...\\n\\nf  = None\\n\\nclass SomeClass(typing.Generic[T, U]):\\n    var: T\\n\\n    def some_method(self) -> T:\\n        global f\\n        def some_fn(a: U) -> U:\\n            ...\\n        f = some_fn\\n        return some_fn(self.var)\\n\\n    def some_method_2(self) -> T:\\n\\n        return some_fn(self.var)\\n\\n    \\nSomeClass().some_method()',\n",
       " 'typing': <module 'typing' from '/usr/local/miniconda3/envs/metadsl/lib/python3.7/typing.py'>,\n",
       " 'T': ~T,\n",
       " 'U': ~U,\n",
       " 'some_fn': <function __main__.some_fn(a: ~U) -> ~U>,\n",
       " 'f': <function __main__.SomeClass.some_method.<locals>.some_fn(a: ~U) -> ~U>,\n",
       " 'SomeClass': __main__.SomeClass,\n",
       " '_i2': 'f.__globals__'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f.__globals__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
